﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightCAD.Core
{
    public static  class MaterialManager 
    {
        private static MaterialCollection materials = new MaterialCollection();
        public const string DefaultUuid = "0";
        public const string MasonryUuid = "288CC2B9-7DA0-BB0B-40BC-EC658CBAB2A0";
        public const string ConcreteUuid = "0F626F79-F2DF-AEE9-011D-81ED8B29460A";
        public const string WoodUuid = "DCF9ACE2-B105-9AE7-C68C-2C7D1FD7DF6A";
        public static LcMaterial DefaultMat => materials[DefaultUuid].Clone();
        public static void Initilize() 
        {
            materials.Add(new LcMaterial() { Color = new Color(0xaaaaaa), Opcity = 1, Uuid = DefaultUuid, Name = "默认" } );
            materials.Add(new LcMaterial() { Color = new Color(0xaaaaaa), Opcity = 1, Uuid = MasonryUuid, Name = "砌体", Texture = @".\Resources\MasonryWall.png" });
            materials.Add(new LcMaterial() { Color = new Color(0xffffff), Opcity = 1, Uuid = ConcreteUuid, Name = "混凝土" });
            materials.Add(new LcMaterial() { Color = new Color(0xffffff), Opcity = 1, Uuid = WoodUuid, Name = "木质" });
        }
        public static LcMaterial GetMaterial(string uuid)=> materials.Contains(uuid)?materials[uuid].Clone(): null;
    }
    public class LcMaterial
    {
        public string Uuid;
        public Color Color = new Color(0xFFFFFF);
        public double Opcity = 1;
        public string Name;
        public string Texture;
        public LcMaterial Clone() 
        {
            return new LcMaterial 
            {
                Uuid = Uuid,
                Color= Color,
                Opcity = Opcity,
                Name = Name,
                Texture = Texture
            };
        }
        public int HashCode => (this.Uuid?? "" + this.Color?.ToString()?? "" + this.Opcity+this.Name?? "" + this.Texture??"").GetHashCode();
        
    }
    public class MaterialCollection : KeyedCollection<string, LcMaterial>
    {
        protected override string GetKeyForItem(LcMaterial item)
        {
            return item.Uuid;
        }
    }
}
